<template>
  <div>
    <h2>学生姓名:{{ name }}</h2>
    <h2>学生年龄：{{ age }}</h2>
    <button @click="sendStudentName">把学生名发给school组件</button>
  </div>
</template>

<script>
import pubsub from "pubsub-js";

export default {
  name: "Student",
  data() {
    return {
      name: "刘虎",
      age: 20,
    };
  },
  methods: {
    sendStudentName() {
      // 谁发谁触发（发布）
      pubsub.publish("hello", this.name);
    },
  },
};
</script>

<style scoped>
div {
  background: gray;
  margin: 30px;
}
</style>